﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;

using LowLevelGraphics;
using LowLevelGraphics.Filter;
using LowLevelGraphics.Forms;

namespace ImageRecognition2.Action
{
    /// <summary>
    /// Action Edge Byte
    /// </summary>
    public class ActionEdgeByte : AbstractCommand
    {
        //private Delegate m_Delegate = null;

        private Type m_Type = typeof(void);

        /// <summary>
        /// Initializes a new instance of the <see cref="ActionEdgeByte"/> class.
        /// </summary>
        /// <param name="_type">The _type.</param>
        public ActionEdgeByte(Type _type)
        {
            m_Type = _type;
        }

        internal ActionEdgeByte(ActionEdgeByte _ActionEdgeByte)
        {
            m_Type = _ActionEdgeByte.m_Type;
        }

        /// <summary>
        /// Runs the specified sender.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        public override void Run(object sender, EventArgs e)
        {
            FormParameter formParameter = new FormParameter();
            if (formParameter.ShowDialog() == DialogResult.OK)
            {
                Bitmap bitmap = (Bitmap)MainFormSingleton.ActivePictureBox.BackgroundImage;
                IFilter filter = (IFilter)Activator.CreateInstance(m_Type, (byte)formParameter.nValue);
                UnsafeBitmap unsafeBitmap = filter.Execute(bitmap);
                unsafeBitmap.Dispose();
            }
        }

        public override object Clone()
        {
            return new ActionEdgeByte(this);
        }
    }
}
